<?php

declare(strict_types=1);

namespace App\Admin\Controller\System\Monitor;


use App\Admin\Annotation\Auth;
use App\Admin\Annotation\Permission;
use App\Admin\Service\System\ServerMonitorService;
use DI\Attribute\Inject;
use Newbie\Annotation\Attributes\Route\Controller;
use Newbie\Annotation\Attributes\Route\GetMapping;
use Newbie\NewbieController;
use support\Response;

/**
 * Class ServerMonitorController
 * @package App\System\Controller\Monitor
 */
#[Controller(prefix: "system/server"), Auth]
class ServerMonitorController extends NewbieController {
    #[Inject]
    protected ServerMonitorService $service;

    /**
     * 获取服务器信息
     */
    #[GetMapping("monitor"), Permission("system:monitor:server")]
    public function getServerInfo (): Response {
        return $this->success([
            'cpu'    => $this->service->getCpuInfo(),
            'memory' => $this->service->getMemInfo(),
            'phpenv' => $this->service->getPhpAndEnvInfo(),
            'net'    => $this->service->getNetInfo(),
            'disk'   => $this->service->getDiskInfo()
        ]);
    }
}